package com.example.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.dao.ChapterMapper;
import com.example.demo.model.Chapter;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.*;

/**
 * 功能描述：
 *
 * @Author: Zhanghf
 * @Date: 2021/12/15 9:02
 */
@Service
public class TextService {

    @Autowired
    private ChapterMapper chapterMapper;
    public String gettext(Integer bookid,Integer chapterid) throws IOException {
        File file = new File("C:\\Knight2.0\\Yunxs\\" + bookid + "\\" + chapterid + ".txt");
        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
        String text = IOUtils.toString(bufferedReader);
        return text;
    }

    public String gettitle(Integer bookid,Integer chapterid)
    {
        Chapter chapter = chapterMapper.selectOne(new QueryWrapper<Chapter>().eq("bookid", bookid).eq("chapterid", chapterid));
        String title = chapter.getChaptername();
        return title;
    }

}
